package cn.itcast.nems.studentrecord.scheduler;

import cn.itcast.nems.common.account.AccountHolder;
import cn.itcast.nems.common.tenant.TenantInfoHolder;
import cn.itcast.nems.studentrecord.service.ClazzEnrollmentCountService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * 定时更新缴费情况
 * </p>
 *
 * @author zhouwei
 * @since 2024/1/4 11:06 AM
 **/
@Component
@RequiredArgsConstructor
@Slf4j
public class ClazzEnrollmentCountJob {
    private  final ClazzEnrollmentCountService clazzEnrollmentCountService ;

    @XxlJob("flushClazzEnrollmentCount")
    public ReturnT<String> flushClazzEnrollmentCount(String param) {
        try {
            AccountHolder.setSchedulerAccountInfo();
            TenantInfoHolder.setDefaultTenantInfo();
            List<Integer> clazzIds = clazzEnrollmentCountService.refresh("true".equalsIgnoreCase(param));
            return new ReturnT<>(JSON.toJSONString(clazzIds , SerializerFeature.DisableCircularReferenceDetect ));
        }finally {
            AccountHolder.clear();
            TenantInfoHolder.clear();
        }

    }
}
